package com.zzl.boot.bigevent.controller;

import com.zzl.boot.bigevent.pojo.*;
import com.zzl.boot.bigevent.service.categoryService;
import com.zzl.boot.bigevent.service.tagService;
import com.zzl.boot.bigevent.service.warehouseService;
import jakarta.validation.constraints.Pattern;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.xml.transform.Result;
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/warehouse")
@Validated
public class warehouseController {
    @Autowired
    private warehouseService service;
    //添加仓库
    @PostMapping("/add")
    public result addwarehouse(String warehouseName) {
        service.add(warehouseName);
        return result.success();
    }
    //获取仓库列表
    @GetMapping("/list")
    public result<List<warehouse>> getAllwarehouse() {
        List<warehouse> list=service.getList();
        return result.success(list);
    }
    //修改仓库
    @PutMapping("/update")
    public result updatewarehouse(@RequestBody  @Validated(warehouse.update.class) warehouse warehouse) {
        service.update(warehouse);
        return result.success();
    }
    //删除仓库
    @DeleteMapping("/del")
    public result delwarehouse(Integer id) {
        service.del(id);
        return result.success();
    }
    //存入仓库
    @PostMapping("/save")
    public result save(@RequestBody articleWarehouse articleWarehouse) {
        if(service.isExit(articleWarehouse)==0){
            service.save(articleWarehouse);
            return result.success();
        }else {
            return result.error("不能重复存入哦!");
        }

    }
    //根据仓库id获取文章
    @GetMapping("/listByWare")
    public result<List<article>> listByWarehouse(Integer warehouseId) {
        List<article> list= service.listByWare(warehouseId);
        return result.success(list);
    }
    //获取仓库的文章数量
    @GetMapping("/count")
    public result<Integer> count(Integer warehouseId) {
        Integer count= service.getcount(warehouseId);
        return result.success(count);
    }
    //移除仓库文章
    @GetMapping("/remove")
    public result remove(Integer wid,Integer aid) {
        service.remove(wid,aid);
        return result.success();
    }
}

